package model

import (
	"github.com/gogf/gf/v2/encoding/gjson"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gtime"
)

// PageSizeReq 分页参数
type PageSizeReq struct {
	Page     int `json:"page" in:"query" d:"1" v:"min:1#分页参数错误" dc:"分页号码，默认1"`
	PageSize int `json:"page_size" in:"query" d:"30" v:"between:1,100#分页数量最大100条" dc:"分页数量，最大100"`
}

// TokenOptions token配置
type TokenOptions struct {
	// Token加密key 32位
	Secret string `json:"secret"`
	// 令牌有效期，单位：秒。默认7天
	Expires int64 `json:"expires"`
	// 缓存key (每创建一个实例CacheKey必须不相同)
	CacheKey string `json:"cacheKey"`
	// 黑名单缓存key
	BlackKey string `json:"blackKey"`
	// 是否允许多端登录
	MultiLogin bool `json:"multiLogin"`
}

// 后台菜单
type (
	SysMenuMetaItem struct {
		Title  string `json:"title"`
		Icon   string `json:"icon"`
		Hidden bool   `json:"hidden"`
		Type   string `json:"type"`
	}
	SysMenuItem struct {
		Id        uint64           `json:"id"`
		Mame      string           `json:"name"`
		Path      string           `json:"path"`
		ParentId  uint64           `json:"parent_id"`
		Meta      *SysMenuMetaItem `json:"meta"`
		Component string           `json:"component"`
	}
	SysMenuTreeItem struct {
		*SysMenuItem
		Children []*SysMenuTreeItem `json:"children"`
	}
	SysMenuOutput struct {
		Menus         []*SysMenuTreeItem `json:"menus"`
		Permissions   []string           `json:"permissions"`
		DashboardGrid []string           `json:"dashboard_grid"`
	}
)

// 账号管理
type (
	AccountInfoItem struct {
		Avatar   string      `json:"avatar"`
		Username string      `json:"username"`
		Nickname string      `json:"nickname"`
		Mobile   string      `json:"mobile"`
		Email    string      `json:"email"`
		Sex      uint        `json:"sex"`
		Birthday *gtime.Time `json:"birthday"`
		Intro    string      `json:"intro"`
		Country  string      `json:"country"`
		Province string      `json:"province"`
		City     string      `json:"city"`
		Address  string      `json:"address"`
	}
	AccountResetPwdInput struct {
		OldPwd  string `json:"old_pwd" v:"required|password3" dc:"原密码"`
		NewPwd  string `json:"new_pwd" v:"required|password3|same:conf_pwd" dc:"新密码"`
		ConfPwd string `json:"conf_pwd" v:"required" dc:"新密码"`
	}
	AccountInfoUpdateInput struct {
		Nickname string      `json:"nickname" v:"max-length:30" dc:"昵称"`
		Sex      uint        `json:"sex" v:"integer|in:0,1,2" dc:"性别"`
		Birthday *gtime.Time `json:"birthday" v:"date" dc:"生日"`
		Intro    string      `json:"intro" v:"max-length:150" dc:"简介"`
		Country  string      `json:"country" v:"max-length:30" dc:"国家"`
		Province string      `json:"province" v:"max-length:30" dc:"省"`
		City     string      `json:"city" v:"max-length:30" dc:"市"`
		Address  string      `json:"address" v:"max-length:150" dc:"详细地址"`
	}
	AccountOpLogsInput struct {
		PageSizeReq
	}
	AccountOpLogsItem struct {
		IpAddress  string      `json:"ip_address"`
		ModuleType string      `json:"module_type"`
		ModuleId   uint64      `json:"module_id"`
		LogAction  string      `json:"log_action"`
		LogRemark  string      `json:"log_remark"`
		CreatedAt  *gtime.Time `json:"created_at"`
	}
	AccountLoginLogsInput struct {
		PageSizeReq
	}
	AccountLoginLogsItem struct {
		IpAddress  string      `json:"ip_address"`
		DeviceInfo string      `json:"device_info"`
		LogType    uint        `json:"log_type"`
		Platform   string      `json:"platform"`
		Browser    string      `json:"browser"`
		LogRemark  string      `json:"log_remark"`
		CreatedAt  *gtime.Time `json:"created_at"`
	}
)

// 上传管理
type (
	UploadFileInput struct {
		File *ghttp.UploadFile `p:"file" type:"file" v:"required" dc:"File to upload"`
	}
	UploadInitMultipart struct {
		UploadId string `json:"uploadId"`
		ExpireIn int64  `json:"expireAt"`
	}
	UploadPartInput struct {
		UploadId   string            `json:"uploadId" v:"required" dc:"上传ID"`
		PartNumber int64             `json:"partNumber" v:"required|integer|between:1,10000" dc:"分片编号"`
		File       *ghttp.UploadFile `p:"file" type:"file" v:"required" dc:"File to upload"`
	}
	UploadPartItem struct {
		PartNumber int64  `json:"partNumber"`
		ETag       string `json:"etag"`
	}
	UploadMultipartInput struct {
		UploadId string            `json:"uploadId" v:"required" dc:"上传ID"`
		Parts    []*UploadPartItem `json:"parts" v:"required|array"`
		FileName string            `json:"fileName"`
		MimeType string            `json:"mimeType"`
	}
	UploadFileItem struct {
		FileName string `json:"file_name"`
		Location string `json:"file_url"`
		Key      string `json:"key"`
		ETag     string `json:"etag"`
	}
	UploadListPartInput struct {
		UploadId         string `json:"uploadId" v:"required" dc:"上传ID"`
		MaxParts         int    `json:"max-parts" v:"integer|between:1,10000"`
		PartNumberMarker int64  `json:"part-number-marker" v:"integer|between:1,10000"`
	}
	UploadListPartItem struct {
		PartNumber int64       `json:"partNumber"`
		ETag       string      `json:"etag"`
		Size       int64       `json:"size"`
		PutTime    *gtime.Time `json:"putTime"`
	}
	UploadListPartOutput struct {
		UploadId             string                `json:"uploadId"`
		ExpireAt             *gtime.Time           `json:"expireAt"`
		PartNumberMarker     int64                 `json:"partNumberMarker"`
		NextPartNumberMarker int64                 `json:"nextPartNumberMarker"`
		ShardCount           int64                 `json:"shardCount"`
		Parts                []*UploadListPartItem `json:"parts"`
	}
	UploadCallbackInput struct {
		Hash   string `json:"hash"`
		Key    string `json:"key"`
		Size   string `json:"size"`
		Bucket string `json:"bucket"`
		Name   string `json:"name"`
	}
)

type (
	// TaskListItem 任务接口
	TaskListItem struct {
		Id         uint64      `json:"id"`
		CreateDate *gtime.Time `json:"createDate"`
		Result     string      `json:"result"`
		State      uint        `json:"state"`
		StateName  string      `json:"stateName"`
		TaskName   string      `json:"taskName"`
		Type       string      `json:"type"`
	}
)

type (
	// ConfigItem 系统配置
	ConfigItem struct {
		ConfKey   string      `json:"conf_key" dc:"配置键"`
		ConfValue *gjson.Json `json:"conf_value" dc:"配置值"`
	}
	// ConfigFormInput 系统配置表单参数
	ConfigFormInput struct {
		ConfKey   string      `json:"conf_key" v:"required|max-length:30" dc:"配置键"`
		ConfValue *gjson.Json `json:"conf_value" v:"required" dc:"配置值"`
	}
)
